feat(net): support domain names in peer configuration#6727
feat(net): support domain names in peer configuration#6727kuny0707 merged 20 commits intotronprotocol:developfrom
Conversation
| api 'org.aspectj:aspectjweaver:1.9.8' | ||
| api 'org.aspectj:aspectjtools:1.9.8' | ||
| api group: 'io.github.tronprotocol', name: 'libp2p', version: '2.2.7',{ | ||
| api group: 'com.github.tronprotocol', name: 'libp2p', version: 'release-v2.2.8-SNAPSHOT',{ |
There was a problem hiding this comment.
Is this release-v2.2.8-SNAPSHOT a correct usage?
Why change from io.github.tronprotocol to com.github.tronprotocol
There was a problem hiding this comment.
It's a gitpack temporary dependency now. After the libp2p v2.2.8 releases, it will be updated as
api group: 'io.github.tronprotocol', name: 'libp2p', version: '2.2.8'
| * @param ipOrDomainWithPort address string in {@code ipOrDomain:port} format | ||
| * @return resolved {@link InetSocketAddress}, or {@code null} if the host cannot be resolved | ||
| */ | ||
| private static InetSocketAddress resolveInetSocketAddress(String ipOrDomainWithPort) { |
There was a problem hiding this comment.
Could you rename resolveInetSocketAddress to resolveInetAddressWithPort, as it will be more clear?
There was a problem hiding this comment.
Class InetSocketAddress already contains InetAddress and Port.
| String ip = inetAddress.getHostAddress(); | ||
| if (localIp.equals(ip)) { | ||
| continue; | ||
| } |
There was a problem hiding this comment.
[SHOULD] Currently, the master and backup servers mainly use external IP addresses, so we can also add external IP address filtering logic.
There was a problem hiding this comment.
Maybe, we can run master and backup in the same node. So, there maybe no need to ignore external IP.
Summary
Allows
node.seed.ip.list,node.active,node.passive,node.fastForward, andnode.backup.membersconfiguration entries to specify domain names in addition to IP literals. Domains are resolved to IPs at startup; backup member IPs are refreshed automatically every 60 seconds when DNS returns a different address.Closes #6634
Problem
All network peer configuration fields previously required numeric IP addresses. Operators running nodes behind dynamic DNS or cloud load-balancers had to manually update config files whenever IPs changed. Backup members in particular need continuous accuracy because they participate in keep-alive health checks.
Changes
New:
InetUtilCentral DNS resolution utility used by both startup parsing and runtime refresh:
resolveInetSocketAddressList(List<String>)— converts a list ofipOrDomain:portstrings toInetSocketAddressobjects. IP literals are used as-is; domain entries are resolved viaLookUpTxt.lookUpIp(IPv4 first, IPv6 fallback). When there are multiple domain entries, resolution is parallelised using a bounded thread pool (up to 10 threads). Unresolvable entries are silently skipped.resolveInetAddress(String)— resolves a bare host (no port) toInetAddress; IP literals take the fast path without a DNS lookup.BackupManager(framework)init(), each configured backup member is resolved viaInetUtil.resolveInetAddress. The resolved IP is stored inmembers; entries with a domain host are additionally tracked in adomainIpCache.dnsExecutorServicescheduler runsrefreshMemberIps()every 60 seconds whendomainIpCacheis non-empty. If DNS returns a new IP, the old IP is removed frommembersand the new IP is added;localIpis never added.dnsExecutorServiceis shut down alongsideexecutorServiceinstop().Args(framework)getInetSockerAddress(config, path)helper that callsInetUtil.resolveInetSocketAddressList, used by bothgetInetSocketAddress(seed/active/passive nodes) andgetInetAddress. Unresolvable domain entries in seed lists are silently dropped; unresolvable backup member entries throwTronError(PARAMETER_INIT)at startup via the newcheckBackupMembers()validator.Dependency
libp2pfromio.github.tronprotocol:libp2p:2.2.7toio.github.tronprotocol:libp2p:2.2.8, which exposes theLookUpTxt.lookUpIpAPI used for DNS resolution.Behaviour Summary
node.backup.membersTronErrorthrown at startup, skip when BackupManager.init() as it will not be triggered until catch upTest
InetUtilTest(18 tests):resolveInetSocketAddressList— IPv4/IPv6 literals, domain resolution, IPv6 fallback, input order preserved, unresolvable entries dropped.resolveInetAddress— same coverage for the no-port variant.BackupManagerTest(6 new tests):init()domain-to-IP mapping and local-IP exclusion;refreshMemberIps()— IP changed, IP unchanged, DNS failure retains old IP.ArgsTest(3 new tests):checkBackupMembers()— IP members pass, unresolvable domain throwsTronError(PARAMETER_INIT), resolvable domain passes.